/**
 * 数据结构栈的实现
 * @module Stacks
 * @date ###### Thu Oct 12 11:01:07 CST 2017
 * @author jinglf000
 */


function Stacks() {
  // private for record stack
  let items = [];

  // push
  this.push = function (element) {
    items.push(element);
  }
  // pop
  this.pop = function(element) {
    return items.pop();
  }
  // toString
  this.toString = function() {
    return items.toString();
  }
  // get last element
  this.peek = function() {
    return items[items.length - 1];
  }
  // isEmpty
  this.isEmpty = function() {
    return items.length === 0;
  }
  // clear
  this.clear = function() {
    items = [];
  }
  // size
  this.size = function() {
    return items.length;
  }
}

module.exports = Stacks;
